package com.alibaba.basic.controller;



import com.alibaba.basic.dto.SMSCodeDto;
import com.alibaba.basic.exception.BusinessException;
import com.alibaba.basic.service.IVerifyCodeService;
import com.alibaba.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.PrivateKey;

@RestController
@RequestMapping("/verifyCode")
public class SmsVerifyCode {
    @Autowired
    private IVerifyCodeService verifyService;

    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody SMSCodeDto smsCodeDto) {

        try {
            verifyService.sendSmsCode(smsCodeDto);
            return new AjaxResult();
        } catch (BusinessException e) {
            e.printStackTrace();
            return new AjaxResult(false, "发送失败，" + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, "系统繁忙!!!");
        }
    }

    /**
     * 获取手机验证码
     * @return
     */
    @PostMapping("/binderSmsCode")
    public AjaxResult binderSmsCode(@RequestBody SMSCodeDto smsDto){
        try {
            verifyService.binderSmsCode(smsDto);
            return new AjaxResult();
        } catch (BusinessException e) {
            e.printStackTrace();
            return new AjaxResult(false,"发送失败，" + e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"系统繁忙!!!");
        }
    }

}
